/**
 *
 * Copyright by Samuel Castro & Joaquim Fonseca, 2011
 * All Rights Reserved
 *
 * NOTES:
 * Please do not redistribute this plugin without my permission
 * Plugin made for private use only
 *
 */
package com.SySammy.sdQuests.Handlers;

import java.io.File;
import java.util.List;
import org.bukkit.util.config.Configuration;

public class yamlHandler {

    private static final File questfile = new File("plugins/RPGmod/Quests/QuestMaker.yml");

    public Configuration load() {
        try {
            Configuration PluginPropConfig = new Configuration(questfile);
            PluginPropConfig.load();
            return PluginPropConfig;

        } catch (Exception e) {
        }
        return null;
    }

    public int NumberOfQuests() {
        Configuration config = load();
        String root = "quests";
        return config.getKeys(root).size();
    }

    public int NumberOfParts(String Quest) {
        Configuration config = load();
        String root = "quests." + Quest;
        return config.getKeys(root).size();
    }

    public String getQuestName(int x) {
        try {
            Configuration config = load();
            String root = "quests";
            return (String) config.getKeys(root).toArray()[x];
        } catch (NullPointerException e) {
            return null;
        }
    }

    public boolean QuestExists(String quest) {
        try {
            Configuration config = load();
            String root = "quests.";
            return config.getKeys(root).contains(quest.toLowerCase());
        } catch (NullPointerException e) {
            return false;
        }
    }

    public String getPartCount(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".details.numberofquests";
        return config.getString(root);
    }

    public String getPartName(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".details.name";
        return config.getString(root);
    }

    public String getInfo(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".details.info";
        return config.getString(root);
    }

    public int getAskedID(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".details.id";
        return config.getInt(root, 0);
    }

    public int getAskedQnt(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".details.qnt";
        return config.getInt(root, 0);
    }

    public String getRewardInfo(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".reward.info";
        return config.getString(root);
    }

    public int getRewardID(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".reward.id";
        return config.getInt(root, 0);
    }

    public int getRewardQnt(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".reward.qnt";
        return config.getInt(root, 0);
    }

    public int getRewardMoney(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".reward.money";
        return config.getInt(root, 0);
    }

    public int getRewardExp(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".reward.exp";
        return config.getInt(root, 0);
    }

    public boolean getCanDie(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".mechanics.candie";
        return config.getBoolean(root, true);
    }

    public List<String> getPerks(String Quest, String part) {
        Configuration config = load();
        String root = "quests." + Quest + "." + "part" + part + ".mechanics.vocations";
        return config.getStringList(root, null);
    }
}
